<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example: DataTable - Inline Editing (YUI Library)</title>
<link type="text/css" rel="stylesheet" href="../../build/reset/reset.css">
<link type="text/css" rel="stylesheet" href="../../build/fonts/fonts.css">
<link type="text/css" rel="stylesheet" href="../../build/logger/assets/logger.css">
<link type="text/css" rel="stylesheet" href="../../build/datatable/assets/datatable.css">
<link type="text/css" rel="stylesheet" href="./css/examples.css">
<link type="text/css" rel="stylesheet" href="../assets/dpSyntaxHighlighter.css">
<style type="text/css">
/* custom css*/
#editing {margin:1em;}
#editing table {border-collapse:collapse;}
#editing th, #editing td {border:1px solid #000;padding:.25em;}
#editing th {background-color:#696969;color:#fff;}/*dark gray*/
#editing .yui-dt-odd {background-color:#eee;} /*light gray*/
#editing .yui-dt-editable.yui-dt-highlight {background-color:#BEDAFF;} /*light blue*/
</style>
</head>
<body>
<div id="hd">
    <h1><img src="./img/logo.gif" class="logo" alt="Y!"/><a href="./">DataTable Widget</a> :: Inline Editing</h1>
</div>
<div id="bd">
    <div id="editing"></div>

    <!-- Sample code begins -->
    <div id="code">
        <h3>Sample Code</h3>

        <p>Data:</p>

        <textarea name="code" class="JScript" cols="60" rows="1">
YAHOO.example.Data.inventory = [
    {SKU:"23-23874", Quantity:43, Item:"Helmet", Description:"Red baseball helmet. Size: Large."},
    {SKU:"48-38835", Quantity:84, Item:"Football", Description:"Leather football."},
    {SKU:"84-84848", Quantity:31, Item:"Goggles", Description:"Light blue swim goggles"},
    {SKU:"84-84843", Quantity:56, Item:"Badminton Set", Description:"Set of 2 badminton rackets, net, and 3 birdies."},
    {SKU:"84-39321", Quantity:128, Item:"Tennis Balls", Description:"Canister of 3 tennis balls."},
    {SKU:"39-48949", Quantity:55, Item:"Snowboard", Description:""},
    {SKU:"99-28128", Quantity:77, Item:"Cleats", Description:"Soccer cleats. Size: 10."},
    {SKU:"83-48281", Quantity:65, Item:"Volleyball", Description:""},
    {SKU:"89-32811", Quantity:67, Item:"Sweatband", Description:"Blue sweatband. Size: Medium."},
    {SKU:"28-22847", Quantity:43, Item:"Golf Set", Description:"Set of 9 golf clubs and bag."},
    {SKU:"38-38281", Quantity:35, Item:"Basketball Shorts", Description:"Green basketball shorts. Size: Small."},
    {SKU:"82-38333", Quantity:288, Item:"Lip balm", Description:"Lip balm. Flavor: Cherry."},
    {SKU:"21-38485", Quantity:177, Item:"Ping Pong Ball", Description:""},
    {SKU:"83-38285", Quantity:87, Item:"Hockey Puck", Description:"Glow-in-the-dark hockey puck."}
];
        </textarea>

        <p>CSS:</p>

        <textarea name="code" class="HTML" cols="60" rows="1">
/* custom css*/
#editing {margin:1em;}
#editing table {border-collapse:collapse;}
#editing th, #editing td {border:1px solid #000;padding:.25em;}
#editing th {background-color:#696969;color:#fff;}/*dark gray*/
#editing .yui-dt-odd {background-color:#eee;} /*light gray*/
#editing .yui-dt-editable.yui-dt-highlight {background-color:#BEDAFF;} /*light blue*/
        </textarea>

        <p>Markup:</p>

        <textarea name="code" class="HTML" cols="60" rows="1">
<div id="editing"></div>
        </textarea>

        <p>JavaScript:</p>

        <textarea name="code" class="JScript" cols="60" rows="1">
var myColumnHeaders = [
    {key:"SKU"},
    {key:"Quantity",editor:"textbox"},
    {key:"Item",editor:"textbox"},
    {key:"Description",editor:"textarea"}
];

var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders);

var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.inventory);
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource.responseSchema = {
    fields: ["SKU","Quantity","Item","Description"]
};

var myDataTable = new YAHOO.widget.DataTable("editing", myColumnSet, myDataSource,{caption:"Example: Inline Editing"});
myDataTable.subscribe("cellClickEvent",myDataTable.onEventEditCell);
myDataTable.subscribe("cellMouseoverEvent",myDataTable.onEventHighlightCell);
myDataTable.subscribe("cellMouseoutEvent",myDataTable.onEventUnhighlightCell);

var onCellEdit = function(oArgs) {
    YAHOO.log("Cell \"" + oArgs.target.id +
            "\" was updated from \"" + oArgs.oldData + "\" to \"" +
            oArgs.newData + "\"", "info", this.toString());
}
myDataTable.subscribe("cellEditEvent",onCellEdit);
        </textarea>
    </div>
    <!-- Code sample ends -->
</div>

<script type="text/javascript" src="../../build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="../../build/dom/dom.js"></script>
<script type="text/javascript" src="../../build/event/event.js"></script>
<script type="text/javascript" src="../../build/logger/logger.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-beta-debug.js"></script>
<script type="text/javascript" src="../../build/datatable/datatable-beta-debug.js"></script>
<script type="text/javascript" src="./js/data.js"></script>
<script type="text/javascript">
var myLogger = new YAHOO.widget.LogReader();

/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
var myColumnHeaders = [
    {key:"SKU"},
    {key:"Quantity",editor:"textbox"},
    {key:"Item",editor:"textbox"},
    {key:"Description",editor:"textarea"}
];

var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders);

var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.inventory);
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource.responseSchema = {
    fields: ["SKU","Quantity","Item","Description"]
};

var myDataTable = new YAHOO.widget.DataTable("editing", myColumnSet, myDataSource,{caption:"Example: Inline Editing"});
myDataTable.subscribe("cellClickEvent",myDataTable.onEventEditCell);
myDataTable.subscribe("cellMouseoverEvent",myDataTable.onEventHighlightCell);
myDataTable.subscribe("cellMouseoutEvent",myDataTable.onEventUnhighlightCell);

var onCellEdit = function(oArgs) {
    YAHOO.log("Cell \"" + oArgs.target.id +
            "\" was updated from \"" + oArgs.oldData + "\" to \"" +
            oArgs.newData + "\"", "info", this.toString());
}
myDataTable.subscribe("cellEditEvent",onCellEdit);
</script>
<script type="text/javascript" src="../assets/dpSyntaxHighlighter.js"></script>
<script type="text/javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</body>
</html>
